﻿using SqlSugar;
using System;
using System.Data;

namespace EyFramework.ORM
{
    public class DbHelper
    {
        private static BaseDaoHis<object> baseDaoHis = new BaseDaoHis<object>();

        /// <summary>
        /// 执行SQL语句
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static DataTable SelectTable(string sql)
        {
            return baseDaoHis.Db.Ado.GetDataTable(sql);
        }

        public static string GetSysDate(string formatStr)
        {
            return baseDaoHis.GetCurrentDate(formatStr);
        }

        public long GetHisMaxId(string tableName, string filedName)
        {
            return baseDaoHis.GetHisMaxId(tableName, filedName);
        }

        public static long GetSequence(string sequenceName, bool createFlag = true)
        {
            return baseDaoHis.GetSequence(sequenceName, createFlag);
        }

        /// <summary>
        /// 执行带参数的SQL语句
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="sqlParameters"></param>
        /// <returns></returns>
        public static DataTable SelectTable(string sql, SugarParameter[] sqlParameters)
        {
            return baseDaoHis.Db.Ado.GetDataTable(sql, sqlParameters);
        }

        /// <summary>
        /// 执行DML更新语句
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static int ExecuteUpdate(string sql)
        {
            return baseDaoHis.Db.Ado.ExecuteCommand(sql);
        }

        /// <summary>
        /// 执行更新带参数
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="sqlParameters"></param>
        /// <returns></returns>
        public static int ExecuteUpdate(string sql, SugarParameter[] sqlParameters)
        {
            return baseDaoHis.Db.Ado.ExecuteCommand(sql, sqlParameters);
        }
    }
}